---
title: "Covid-19 in Egypt"
date: "Last update: `r Sys.time()`"
author: Sherif Embarak^[https://github.com/Sherif-Embarak/]
output:
flexdashboard::flex_dashboard:
theme: lumen
social: menu
source: embed
vertical_layout: scroll
orientation: rows
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
rm(list=ls(all=TRUE))
options(stringsAsFactors = FALSE)
library(ggplot2)
library(plotly)
library(flexdashboard)
library(DT)
library(plotly)
library(knitr)
library(lubridate)
library(crosstalk)
setwd("D:/work/git corona/")
df <- read.csv("eg_covid.csv")
df$Day <- mdy(df$Day)
df$Day <- paste(day(df$Day) , months.Date(df$Day) )
df$Curfew <- as.character(df$Curfew)
df <- df[,1:8]
total_cases <- df$Total.Cases[nrow(df)]
total_deaths <- df$Total.Deaths[nrow(df)]
total_recovered <- df$Total.Recovered[nrow(df)]
closed <- total_deaths+total_recovered
active <- total_cases - closed
library(crosstalk)
df$Day <- factor(df$Day, levels = df$Day)
xlabel <- df$Day[as.integer(seq(1 , nrow(df) , length.out = 10))]
hk <- highlight_key(df, ~Total.Cases)
chart1 <-ggplotly(ggplot(hk, aes(x=Day, y=New.Cases, fill=Curfew)) + scale_x_discrete(breaks = xlabel)+
geom_bar(width = 0.3, stat = "identity")+scale_fill_manual(values = c("#6698FF", "#153E7E"))+
theme(panel.grid.major.x = element_blank(), axis.text.x = element_text(angle = 70, hjust = 1)),tooltip = c("x", "y")) %>%
highlight(off = "plotly_relayout")
chart2 <-ggplotly(ggplot(hk, aes(x=Day, y=New.Deaths, fill=Curfew)) + scale_x_discrete(breaks = xlabel)+
geom_bar(width = 0.3, stat = "identity")+scale_fill_manual(values = c("#6698FF", "#153E7E"))+
theme(panel.grid.major.x = element_blank(), axis.text.x = element_text(angle = 70, hjust = 1)),tooltip = c("x", "y")) %>%
highlight(off = "plotly_relayout")
chart3 <-ggplotly(ggplot(hk, aes(x=Day, y=New.Recovered, fill=Curfew)) + scale_x_discrete(breaks = xlabel)+
geom_bar(width = 0.3, stat = "identity")+scale_fill_manual(values = c("#6698FF", "#153E7E"))+
theme(panel.grid.major.x = element_blank(), axis.text.x = element_text(angle = 70, hjust = 1)),tooltip = c("x", "y")) %>%
highlight(off = "plotly_relayout")
chart4 <- ggplotly(ggplot(data=hk, aes(x=Day, y=Total.Cases, group=1))+ scale_x_discrete(breaks = xlabel)+
geom_line(color="#33CCFF", size=1)+theme(panel.grid.major.x = element_blank(), axis.text.x = element_text(angle = 70, hjust = 1))+
geom_point(color="#33CCFF"),tooltip = c("x", "y")) %>%
highlight(off = "plotly_relayout")
chart5 <- ggplotly(ggplot(data=hk, aes(x=Day, y=Total.Deaths, group=1))+ scale_x_discrete(breaks = xlabel)+
geom_line(color="#FF9900", size=1)+theme(panel.grid.major.x = element_blank(), axis.text.x = element_text(angle = 70, hjust = 1))+
geom_point(color="#FF9900"),tooltip = c("x", "y")) %>%
highlight(off = "plotly_relayout")
chart6 <- ggplotly(ggplot(data=hk, aes(x=Day, y=Total.Recovered, group=1))+ scale_x_discrete(breaks = xlabel)+
geom_line(color="#00DDDD", size=1)+theme(panel.grid.major.x = element_blank(), axis.text.x = element_text(angle = 70, hjust = 1))+
geom_point(color="#00DDDD"),tooltip = c("x", "y"))%>%
highlight(off = "plotly_relayout")
```
Dashboard
=======================================================================
Row
-----------------------------------------------------------------------
### Total Coronavirus Cases in Egypt
```{r, echo=FALSE}
valueBox(total_cases)
```
### Total Coronavirus Deaths in Egypt
```{r, echo=FALSE}
valueBox(total_deaths, color="warning")
```
### Total Coronavirus Recovered Cases in Egypt
```{r, echo=FALSE}
valueBox(total_recovered , color = "#00DDDD")
```
### Cases which had an outcome `r ""` `r paste0("Deaths/Discharged : ", total_deaths, " (", round((total_deaths/closed)*100,1),"%)" )` `r ""` `r paste0("Recovered/Discharged : ", total_recovered, " (", round((total_recovered/closed)*100,1),"%)" )`
```{r, echo=FALSE}
valueBox(paste("Closed Cases: ",closed))
```
### Currently Infected Patients
```{r, echo=FALSE}
valueBox(paste("Active Cases: ",active))
```
Row
-------------------------------------
### Confirmed Cases per day
```{r, echo=FALSE ,fig.height=3}
chart1
```
### Deaths per day
```{r, echo=FALSE ,fig.height=3}
chart2
```
### Recovered Cases per day
```{r, echo=FALSE ,fig.height=3}
chart3
```
Row
-------------------------------------
### Total Confirmed Cases
```{r, echo=FALSE, warning=FALSE,message=FALSE,results='asis',fig.show='asis'}
chart4
```
### Total Deaths
```{r, echo=FALSE, warning=FALSE,message=FALSE,results='asis',fig.show='asis'}
chart5
```
### Total Recovered
```{r, echo=FALSE, warning=FALSE,message=FALSE,results='asis',fig.show='asis'}
chart6
```
Column {.sidebar data-width=350}
-------------------------------------
### Distibution of Cases
This dashboard has been created according to worldometers.info design. In order to compensate with the lack of real time statistical data in Egypt, the given data below will be updated daily at 10:00 PM (Cairo Time).
Stay Home, Stay Safe.
```{r, echo=FALSE }
DT::datatable(hk,class = 'cell-border stripe hover compact', rownames = FALSE , options = list(pageLength = 10,order = list(2, 'desc')))%>%
formatStyle('New.Cases', backgroundColor = '#FFEEAA') %>%
formatStyle('New.Deaths',backgroundColor = 'red')%>%
formatStyle(names(df),fontWeight = 'bold')%>%
formatStyle('Curfew', backgroundColor = styleEqual(c(0, 1), c('#a6cee3', '#1f78b4')))%>%
highlight(on = "plotly_click" , off ="plotly_doubleclick")
```